﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WaterlevelUpdate.aspx.cs" Inherits="GroundWater.waterlevel.WaterlevelUpdate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
<link href="../ext.css" type="text/css" rel="Stylesheet" />
    
    <script language="javascript" src="../js/common.js" type="text/javascript"></script>
    <script language="javascript" src="../js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js"></script>
    
    <link media=all href="../js/resources/_Common/Common.css" type=text/css rel=stylesheet>
    <link media=all href="../js/resources/_Loadding/Loadding.css" type=text/css rel=stylesheet>
    <link media=all href="../js/resources/_Panel/Panel.css" type=text/css rel=stylesheet>
    <link media=all href="../js/resources/_Button/Button.css" type=text/css rel=stylesheet>
    <link media=all href="../js/resources/_TextBox/TextBox.css" type=text/css rel=stylesheet>
</head>
<body>
    <form id="form1" runat="server"><asp:ScriptManager ID="scriptManager" runat="server" />
<!-- 面板内容 -->                
<div id=bodyPanel style="width:92%; margin-right:8px;">
<div class=x-pne id=panel style="WIDTH: 100%;">
    <div class="corner-bg x-pne-lt x-pne-left">
    <div class="corner-bg x-pne-rt x-pne-right">
    <div class="corner-bg x-pne-t">
    <div class="x-pne-caption font">查询条件</div>
    </div>
    </div>
    </div>
    
    <div>
    <div class="side-bg x-pne-l">
    <div class="side-bg x-pne-r">
    <div class="x-pne-c" style="WIDTH: 100%; HEIGHT: 38px">
    <div id="contentPanel"><!-- 控件实例 -->

    <div class="gbPanel"><%--onselectedindexchanged="drpWell_SelectedIndexChanged"--%>
        <table class="font">
        <tbody>
        <tr>
            <td>水井:</td><td><asp:DropDownList ID="drpWell" runat="server"
                DataSourceID="odsWells" DataTextField="Name" DataValueField="Code"  OnSelectedIndexChanged="drpWell_SelectedIndexChanged"
                EnableViewState="false" AutoPostBack="true" ></asp:DropDownList></td>
            <td>日期从:</td><td><input class="textField text-bg border-blur" id="txtStartDate"  type="text" maxlength="16" style="width:76px;" runat="server" />&nbsp;<img onclick="WdatePicker({el:$dp.$('txtStartDate')})" src="../js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle" /></td>
            <td>到:</td><td><input class="textField text-bg border-blur" id="txtEndDate"  type="text" maxlength="16" style="width:76px;" runat="server"/>&nbsp;<img onclick="WdatePicker({el:$dp.$('txtEndDate')})" src="../js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle" /></td>
            <td style="padding-left:30px;">
                <div>
                    <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
                    <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnQuery" runat="server" Text="查　询" CssClass="font" onclick="btnQuery_Click" OnClientClick="if(!isDate(txtStartDate) || !isDate(txtEndDate)) { alert('日期格式不正确！'); return false; }" /></div>  <%--<button id="btnQuery" name="btnQuery" class=font type=button runat="server" onclick="__doPostBack(this, null);">查　询</button>--%>
                    <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
                </div>
            </td>
            <td style="padding-left:30px;">
                <div>
                    <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
                    <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnOK" runat="server" Text="  导出  " CssClass="font" OnClick="btnExport_Click" OnClientClick="if(!isDate(txtStartDate) || !isDate(txtEndDate)) { alert('日期格式不正确！'); return false; }" /></div>  <%--<button id="btnQuery" name="btnQuery" class=font type=button runat="server" onclick="__doPostBack(this, null);">查　询</button>--%>
                    <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
                </div>
            </td>
        </tr>
        </tbody>
        </table>
    </div>

    </div>
    </div>
    </div>
    </div>
    <div class="corner-bg x-pne-lb x-pne-left">
        <div class="corner-bg x-pne-rb x-pne-right">
            <div class="corner-bg x-pne-b"></div>
        </div>
    </div>
    </div>
</div>
</div>
<asp:ObjectDataSource ID="odsWells" runat="server" SelectMethod="GetAllWithCode" TypeName="GroundWater.BusinessActions.Well" >
<%--    <SelectParameters>
        <asp:Parameter Name="isStoredProc" Type="Boolean" DefaultValue="False" />
        <asp:Parameter Name="enableCache" Type="Boolean" DefaultValue="True" />
    </SelectParameters>--%>
</asp:ObjectDataSource>

<!-- 面板内容结束 -->
<%--
    <asp:ObjectDataSource ID="odsMonitoring" runat="server" SelectMethod="GetAll" 
        TypeName="GroundWater.BusinessActions.Monitoring" 
        onselecting="odsMonitoring_Selecting" >
    <SelectParameters>
        <asp:Parameter Name="isStoredProc" Type="Boolean" DefaultValue="False" />
        <asp:Parameter Name="enableCache" Type="Boolean" DefaultValue="False" />
    </SelectParameters>
    </asp:ObjectDataSource>
    --%>
    
 <asp:ObjectDataSource id="odsMonitoring" runat="server" EnablePaging="True" 
     TypeName="GroundWater.BusinessActions.Monitoring" 
     SelectMethod="FetchPaged" SelectCountMethod="FetchRowCount"
     SortParameterName="sortExpression" OnSelecting="odsMonitoring_Selecting">
    <SelectParameters>
    <asp:ControlParameter ControlID="drpWell" PropertyName="SelectedValue" Name="wellCode" />
    <asp:ControlParameter ControlID="txtStartDate" PropertyName="Value" Name="startDate" />
    <asp:ControlParameter ControlID="txtEndDate" PropertyName="Value" Name="endDate" />
      <%--<asp:Parameter Name="wellCode" Type="String"  />
      <asp:Parameter Name="whereClause" Type="String" />
      <asp:Parameter Name="whereClause" Type="String" />
      <asp:Parameter Name="whereClause" Type="String" />--%>
    </SelectParameters>
</asp:ObjectDataSource>

    <div style="width:96%; margin-top:10px;">
        <p style="font-weight:bold; font-family:Tahoma; margin-bottom:8px; "></p>
        <div class="grid">
            <div class="rounded">
                <div class="top-outer"><div class="top-inner"><div class="top">
                    <h2>水位数据 </h2>
                </div></div></div>
                <div class="mid-outer"><div class="mid-inner"><div class="mid">     
                
                    <!-- Content Goes Here! -->
                    <asp:UpdatePanel ID="updPanel" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:GridView 
                                ID="gvMonitoring" runat="server" DataSourceID="odsMonitoring" SkinID="PagingGridView" DataKeyNames="WellCode, MonitorTime"
                                OnRowDataBound="RowDataBound" 
                                onselectedindexchanging="gvMonitoring_SelectedIndexChanging" >
                                <Columns>
                                    <asp:BoundField  HeaderText="水井名称" DataField="WellName" SortExpression="WSWLNM" HeaderStyle-CssClass="first" ItemStyle-CssClass="first" />
                                    <asp:BoundField  HeaderText="检测时间" DataField="MonitorTime"   DataFormatString="{0:yyyy-MM-dd HH:mm}" HtmlEncode="false"  SortExpression="MNTM"  />
                                    <asp:BoundField  HeaderText="水位" DataField="Waterlevel"   SortExpression="Z"  DataFormatString="{0:N2}"   />
                                    <asp:BoundField  HeaderText="埋深" DataField="Altitude" SortExpression="Altitude" DataFormatString="{0:N2}"  />
                                    <asp:BoundField  HeaderText="卡号" DataField="SIMCard"     SortExpression="COMMNO"  />
                                    <asp:BoundField  HeaderText="设备地址" DataField="BTUAddress"    SortExpression="CONTROLLERID"   />
                                    <asp:BoundField  HeaderText="剖面" DataField="SectionPlane"   SortExpression="NT"  />
                                    <asp:TemplateField><ItemTemplate><asp:LinkButton id="btnEdit" runat="server" CommandName="Select" OnClick="btnEdit_Click">编辑</asp:LinkButton></ItemTemplate></asp:TemplateField>
                                    <asp:CommandField ShowDeleteButton="true" DeleteText="删除" />
                                </Columns>
                            </asp:GridView>   
                        </ContentTemplate>
                        <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnQuery" />
                        <asp:AsyncPostBackTrigger ControlID="drpWell" EventName="SelectedIndexChanged" />
                        </Triggers>
                    </asp:UpdatePanel>                     
    
                </div></div></div>
            <div class="bottom-outer"><div class="bottom-inner">
            <div class="bottom"></div></div></div>                   
        </div>      
        </div>
    </div>
    
    
        <!-- 面板内容 -->                
<div id="Div1">

<asp:Panel ID="PopupPanel" runat="server" CssClass="x-pne" style="display:none; z-index:9999;  width:500px;">

<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
    <asp:HiddenField ID="hidWellCode" runat="server" />
    <asp:HiddenField ID="hidMonitorTime" runat="server" />
<asp:Button id="btnShowPopupHelper" runat="server" style="display:none" />

    <ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server" 
    BehaviorID="popupBehavior" 
    TargetControlID="btnShowPopupHelper" 
    PopupControlID="PopupPanel" 
    DropShadow="false"
    PopupDragHandleControlID="DragPanel"
    BackgroundCssClass="modalBackground"
    CancelControlID="btnClose" />

    <asp:Panel ID="DragPanel" runat="server" CssClass="corner-bg x-pne-lt x-pne-left">
    <div class="corner-bg x-pne-rt x-pne-right">
    <div class="corner-bg x-pne-t drag">
    <div class=x-pne-btn style="background-position: 0px 0px" onclick="$find('popupBehavior').hide();" ></div>
    <div class="x-pne-caption font drag">编辑水位监测信息</div>
    </div>
    </div>
    </asp:Panel>
    
    <div>
    <div class="side-bg x-pne-l">
    <div class="side-bg x-pne-r">
    <div class="x-pne-c" style="WIDTH: 488px; HEIGHT: 220px">
    <div id="Div2"><!-- 控件实例 -->
<%--<asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtName"   maxlength="16" /><span class="warning">*</span>--%>
    <div class="gbPanel">
<table id="tblWell" class="font" style="width: 100%;">
    <tr>
        <td>水井名称</td><td><asp:DropDownList ID="drpWells" runat="server" DataSourceID="odsWells" DataTextField="Name" DataValueField="Code" EnableViewState="false" AutoPostBack="true" OnSelectedIndexChanged="drpWells_SelectedIndexChanged" ></asp:DropDownList></td>
        <td>水井代码</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtCode"   maxlength="16" /><span class="warning">*</span></td>
        
    </tr>
    <tr>
        <td>监测时间</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtMonitorTime"    />&nbsp;<img onclick="WdatePicker({el:$dp.$('txtMonitorTime'), dateFmt:'yyyy-MM-dd HH:mm'})" src="../js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle" /><span class="warning">*</span></td>
        <td>电池电压</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtCellVoltage"    /><span class="warning">*</span></td>
    </tr>
    <tr>
        <td>水位</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtWaterlevel"   /><span class="warning">*</span></td>
        <td>原始水位</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtOriginalWaterLevel"   /><span class="warning">*</span></td>
    </tr>
    <tr>
        <td>流量</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtFlowRate"    /></td>
        <td>水压</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtHydraulicPressure"   /></td>
    </tr>
    <tr>
        <td>水质类别</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtWaterQuality"   /></td>
        <td>剖面</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtSectionPlane"    /></td>
    </tr>
    <tr>
        <td>卡号</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtSIMCard"    /></td>
        <td>设备地址</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtBTUAddress"   /><span class="warning">*</span></td>
    </tr>
    
    
</table>
    </div>

    <div class="gbPanel" style="margin-top:20px; text-align:center;">
    <table class="method-area1" style="margin:0 auto; text-align:left;">
    <tbody>
    <tr>
    <td style="padding-left:60px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="Button1" runat="server" Text="保  存" CssClass="font" OnClick="btnOK_Click" OnClientClick="return validateWell();" /></div><%----%>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    <td style="padding-left:60px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnClose" runat="server" Text="取  消" CssClass="font" /></div>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    </tr>

    </tbody>
    </table>
    </div>


    </div>
    </div>
    </div>
    </div>
    
    <div class="corner-bg x-pne-lb x-pne-left">
        <div class="corner-bg x-pne-rb x-pne-right">
            <div class="corner-bg x-pne-b"></div>
        </div>
    </div>
    </div>
    
     </ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" />
</Triggers>
 </asp:UpdatePanel>
</asp:Panel>

</div>
<!-- 面板内容结束 -->
    
    <div style="margin-left:36px; margin-top:10px;"><asp:Button ID="btnAdd" runat="server" Text="添加水位监测信息" CssClass="BigButton" OnClick="btnAdd_Click" /></div>
    
    
    
<asp:updateprogress id="updateProgress" runat="server" DynamicLayout="true" DisplayAfter="300">
    <progresstemplate>
        <div id="progressBackgroundFilter"></div>
        <div id="processMessage">正在处理数据，请稍等...<br /><br /><img alt="Loading" src="../images/loading_16.gif" /></div>
    </progresstemplate>
</asp:updateprogress>
    </form>
    
    <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function() {

            jQuery.each(jQuery("input", jQuery(".gbPanel")), function() {
                jQuery(this).bind("mousemove", function() {
                    var center = this.parentNode;
                    center.previousSibling.style.backgroundPosition = "0px 147px";
                    center.style.backgroundPosition = "0px 105px";
                    center.nextSibling.style.backgroundPosition = "0px 126px";
                });
                jQuery(this).bind("mouseout", function() {
                    var center = this.parentNode;
                    center.previousSibling.style.backgroundPosition = "";
                    center.style.backgroundPosition = "0px 168px";
                    center.nextSibling.style.backgroundPosition = "0px 189px";
                });


            }, null);

            jQuery("#drpWell").change(function() {
                if (this.selectedIndex == 0) {
                    //__doPostBack('drpWell', '');
                    setTimeout(__doPostBack, 0);
                }
            });
//            jQuery("#drpWells").change(function() {
//            var wellCode = this.options[this.selectedIndex].value;
//            jQuery.post(
//                    "WellHandler.ashx?op=fetch",
//                    { "wellcode": wellCode },
//                    function(data) {
//                        var well = Sys.Serialization.JavaScriptSerializer.deserialize(data);
//                        if (data) {
//                            populateWellInfo(well);
//                        }
//                    },
//                    "text");
//            });
        });

        function setFields() {
            var el = document.getElementById("drpWells");
            var wellCode = el.options[el.selectedIndex].value;


            var requestBody = new Sys.StringBuilder();
            requestBody.append("wellcode");
            requestBody.append('=');
            requestBody.append(encodeURIComponent(wellCode));

            var webRequest = new Sys.Net.WebRequest();
            webRequest.set_url('WellHandler.ashx?op=fetch');
            webRequest.set_httpVerb('POST');
            webRequest.set_body(requestBody.toString());
            webRequest.add_completed(completedHandler);
            webRequest.invoke();
            
//            jQuery.post(
//                    "WellHandler.ashx?op=fetch",
//                    { "wellcode": wellCode },
//                    function(data) {
//                        var well = Sys.Serialization.JavaScriptSerializer.deserialize(data);
//                        if (data) {
//                            populateWellInfo(well);
//                        }
//                    },
//                    "text");
        }
        

        function populateWellInfo(well) {
            jQuery("#txtCode", "#tblWell").val(well.WellCode);
            //jQuery("#txtWellName", "#tblWell").val(well.WellName);
            //jQuery("#txtLongitude", "#tblWell").val(well.Longitude);
            //jQuery("#txtLatitude", "#tblWell").val(well.Latitude);
            //jQuery("#txtDepth", "#tblWell").val(well.Depth);
            //jQuery("#txtShaftSinkingDate", "#tblWell").val(well.ShaftSinkingDate.format("yyyy-MM-dd"));
            jQuery("#txtSIMCard", "#tblWell").val(well.SIMCard);
            jQuery("#txtBTUAddress", "#tblWell").val(well.BTUAddress);
            jQuery("#txtSectionPlane", "#tblWell").val(well.SectionPlane)
        }
        //]]>
        function btnQuery_onclick() {

        }

        function validateWell() {

            var message = "";
            if (!notEmpty($get("txtCode"))) {
                message += "水源地代码不能为空。\n";
            }
//            if (!notEmpty($get("txtName"))) {
//                message += "水源地名称不能为空。\n";
//            }

            if (!notEmpty($get("txtMonitorTime"))) {
                message += "监测时间不能为空。\n";
            }
            if (!notEmpty($get("txtWaterlevel"))) {
                message += "水位不能为空。\n";
            }
            if (!notEmpty($get("txtSIMCard"))) {
                message += "设备卡号。\n";
            }
            if (!notEmpty($get("txtBTUAddress"))) {
                message += "设备地址。\n";
            }
            if (!notEmpty($get("txtSectionPlane"))) {
                message += "剖面不能为空。\n";
            }


            if (!isNum($get("txtWaterlevel").value)) {
                message += "水位为数值。\n";
            }
            if (!isNum($get("txtCellVoltage").value)) {
                message += "电池电压为数值。\n";
            }
            if (!isNum($get("txtOriginalWaterLevel").value)) {
                message += "原始水位为数值。\n";
            }
            if (!isNum($get("txtFlowRate").value)) {
                message += "流量为数值。\n";
            }
            if (!isNum($get("txtHydraulicPressure").value)) {
                message += "水压为数值。\n";
            }


            if ($get("txtWaterQuality").value.length > 1) {
                message += "水质类别长度不大于1。\n";
            }

//            if (!validateCNDate($get("txtProductDate").value)) {
//      message += "监测时间格式不正确。";
//            }

            if (message.length > 0) {
                alert(message);
                return false;
            }
            return true;
        }

        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(endRequestHandler);

        function endRequestHandler(sender, args) {
            var dataItems = args.get_dataItems();
//            var error = args.get_error();
//            var errorHandled = args.get_errorHandled();
            //            var response = args.get_response();
            //Sys.UI.DomEvent.addHandler($get("drpWells"), "change", setFields);
            if (dataItems['txtCode'] && dataItems['txtCode'] == "0") {

                alert("您输入的监测时间格式不正确。");
            }

//            if (dataItems['txtCode'] && dataItems['txtCode'].length > 0) {
//                var s = dataItems['txtCode'].split('|');
//                $get("txtCode").value = s[0];
//                $get("txtSectionPlane").value = s[1];
//                $get("txtSIMCard").value = s[2];
//                $get("txtBTUAddress").value = s[3];
//            }
        }

        function completedHandler(response, eventArgs) {
            if (response.get_aborted()) {
                // Abort
                alert("请求被终止！");
            }
            else if (response.get_responseAvailable()) {
                var statusCode = response.get_statusCode();

                if (((statusCode < 200) || (statusCode >= 300))) {
                    // Error
                    alert(statusCode + response.get_responseData());
                }
                else {
                    // Success
                    var well = Sys.Serialization.JavaScriptSerializer.deserialize(response.get_responseData());
                    //alert('ffff');
                    populateWellInfo(well);
                }
            }
            else {
                if (response.get_timedOut()) {
                    // Timeout
                }
                else {
                    // Error
                }
            }
        }

        function pageLoad() {
            var mpe = $find("popupBehavior");
            //mpe.add_shown(onShown);
            mpe.add_hidden(onHidden);
        }
        function onHidden()
        {
            document.getElementById("hidWellCode").value = "";
            document.getElementById("hidMonitorTime").value = "";

            //alert("onHidden");
        }
    </script>
<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js"></script>
<asp:Literal ID="lblJavaScript" EnableViewState="false" runat="server"></asp:Literal>
</body>
</html>